#Fichero: Makefile

##############################
###### CONFIGURACION #########
##############################

BIN = ./bin
LIB = ./lib
OBJ = ./obj

DEFS = ./CORBA_defs
IMPLS = ./CORBA_impl
SKELS = ./CORBA_skel

MAIN = .
META = ./awareness
META_CLIENT = $(META)/client
META_CLIENT_DEFAULTS = $(META_CLIENT)/defaults
META_SERVER = $(META)/server
META_UTIL = $(META)/functions
AUXILIARY = ./auxiliary
EVENTS = ./events
MYSQL = /usr/local/mysql

INCLUDE = -I$(SKELS)/ -I$(IMPLS)/ -I$(META)/ -I$(META_CLIENT)/ -I$(META_SERVER)/ -I$(META_UTIL)/ -I$(AUXILIARY) -I$(EVENTS)/ -I$(MYSQL)/include/ -I$(MAIN)/ -I$(META_CLIENT_DEFAULTS)
SRC_COMPILER = g++
LD = ld
AR = ar
IDL_COMPILER = omniidl
IDL_OPTS = -bcxx -Wbexample -Wba -I$(DEFS)/ -C$(SKELS)/ -Wbh=.h -Wbs=SK.cpp

CXX_OPTS = -O0 -fno-common -fPIC -Wall -g -bind_at_load -D_REENTRANT -D__OMNIORB4__ -D__OSVERSION__=1 -D__darwin__ -D__x86__ -fno-inline
CXX_OPTS_MYSQL = -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT $(OPTS)
CXX_LIB_PATHS = -L$(MYSQL)/lib/
CXX_OMNI_LIBS = -lomniORB4 -lomniDynamic4 -lomniThread -lCOS4
CXX_LIBS = $(CXX_LIB_PATHS) $(CXX_OMNI_LIBS) -lmysqlclient -lz -lm -lmygcc

LINKOPTS = rcs
DYNLINKOPTS = -dynamic -bundle -flat_namespace -undefined suppress
DYNLINKIMPORTS = /usr/lib/bundle1.o

OBJS_SKEL = $(OBJ)/collaborationDynSK.o $(OBJ)/collaborationSK.o
OBJS_IMPL = $(OBJ)/MIDataAccessor.o

OBJS_MAIN_CLIENT = $(OBJ)/test_client.o
OBJS_MAIN_SERVER = $(OBJ)/MIService.o

OBJS_EVENTS = $(OBJ)/eventConsumer.o $(OBJ)/eventSupplier.o $(OBJ)/event.o $(OBJ)/eventListener.o $(OBJ)/eventHandler.o $(OBJ)/listeningObject.o

OBJS_META = 
OBJS_META_CLIENT = $(OBJ)/MI_client.o $(OBJ)/MIServiceConnector.o $(OBJ)/collaboration_subsystem.o
OBJS_META_CLIENT_DEFAULTS = $(OBJ)/MIListener.o $(OBJ)/MIEvent.o $(OBJ)/pairEvent.o $(OBJ)/drawingEvent.o $(OBJ)/drawingListener.o
OBJS_META_SERVER = $(OBJ)/dbAccessor.o $(OBJ)/dbConnector.o $(OBJ)/MI_server.o
OBJS_META_UTIL = $(OBJ)/MIRole.o $(OBJ)/MIUser.o $(OBJ)/MIApplication.o

OBJS_AUXILIARY = $(OBJ)/Thread.o

OBJS_SERVER = $(OBJS_SKEL) $(OBJS_IMPL) $(OBJS_META) $(OBJS_META_UTIL) $(OBJS_META_SERVER) $(OBJS_AUXILIARY) $(OBJS_EVENTS)
OBJS_CLNT = $(OBJS_SKEL) $(OBJS_META) $(OBJS_META_UTIL) $(OBJS_META_CLIENT) $(OBJS_AUXILIARY) $(OBJS_EVENTS) $(OBJS_META_CLIENT_DEFAULTS)

.PHONY = all clean

##############################
##### DESTINOS VIRTUALES #####
##############################

all: $(LIB)/collaboration.dylib $(LIB)/libcollaboration.a $(BIN)/test_client $(BIN)/MIService

clean:
	rm $(OBJ)/*
	rm $(LIB)/*
	rm $(BIN)/test_client
	rm $(BIN)/MIService

#############################
######  BIBLIOTECAS  ########
#############################

$(LIB)/collaboration.dylib : $(OBJS_CLNT)
	$(LD) -o $(LIB)/collaboration.dylib $(OBJS_CLNT) $(DYNLINKOPTS) $(DYNLINKIMPORTS)

$(LIB)/libcollaboration.a : $(OBJS_CLNT)
	$(AR) $(LINKOPTS) $(LIB)/libcollaboration.a $(OBJS_CLNT)

#############################
###### EJECUTABLES ##########
#############################

$(BIN)/test_client : $(OBJS_MAIN_CLIENT) $(LIB)/libcollaboration.a
	$(SRC_COMPILER) -o $(BIN)/test_client $(OBJS_MAIN_CLIENT) -L$(LIB)/ -lcollaboration $(CXX_OPTS) $(CXX_OMNI_LIBS)

$(BIN)/MIService : $(OBJS_SERVER) $(OBJS_MAIN_SERVER)
	$(SRC_COMPILER) -o $(BIN)/MIService $(OBJS_SERVER) $(OBJS_MAIN_SERVER) $(CXX_OPTS) $(CXX_LIBS)

##############################
######   CORBA_SKEL   ########
##############################

$(SKELS)/collaboration.h : $(DEFS)/collaboration.idl
	$(IDL_COMPILER) $(IDL_OPTS) $(DEFS)/collaboration.idl
	
$(OBJ)/collaborationDynSK.o : $(SKELS)/collaboration.h $(SKELS)/collaborationDynSK.cc
	$(SRC_COMPILER) -c $(SKELS)/collaborationDynSK.cc -o $(OBJ)/collaborationDynSK.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/collaborationSK.o : $(SKELS)/collaboration.h $(SKELS)/collaborationSK.cpp
	$(SRC_COMPILER) -c $(SKELS)/collaborationSK.cpp -o $(OBJ)/collaborationSK.o $(CXX_OPTS) $(INCLUDE)

##############################
######   CORBA_IMPLS   #######
##############################

$(OBJ)/MIDataAccessor.o : $(IMPLS)/MIDataAccessor.cpp $(IMPLS)/MIDataAccessor.h
	$(SRC_COMPILER) -c $(IMPLS)/MIDataAccessor.cpp -o $(OBJ)/MIDataAccessor.o $(CXX_OPTS) $(INCLUDE)

#############################
#######   EVENTS     ########
#############################

$(OBJ)/eventConsumer.o : $(EVENTS)/eventConsumer.cpp $(EVENTS)/eventConsumer.h
	$(SRC_COMPILER) -c $(EVENTS)/eventConsumer.cpp -o $(OBJ)/eventConsumer.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/eventSupplier.o : $(EVENTS)/eventSupplier.cpp $(EVENTS)/eventSupplier.h
	$(SRC_COMPILER) -c $(EVENTS)/eventSupplier.cpp -o $(OBJ)/eventSupplier.o $(CXX_OPTS) $(INCLUDE)
	
$(OBJ)/event.o : $(EVENTS)/event.cpp $(EVENTS)/event.h
	$(SRC_COMPILER) -c $(EVENTS)/event.cpp -o $(OBJ)/event.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/eventListener.o : $(EVENTS)/eventListener.cpp $(EVENTS)/eventListener.h
	$(SRC_COMPILER) -c $(EVENTS)/eventListener.cpp -o $(OBJ)/eventListener.o $(CXX_OPTS) $(INCLUDE)
	
$(OBJ)/eventHandler.o : $(EVENTS)/eventHandler.cpp $(EVENTS)/eventHandler.h
	$(SRC_COMPILER) -c $(EVENTS)/eventHandler.cpp -o $(OBJ)/eventHandler.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/listeningObject.o : $(EVENTS)/listeningObject.cpp $(EVENTS)/listeningObject.h
	$(SRC_COMPILER) -c $(EVENTS)/listeningObject.cpp -o $(OBJ)/listeningObject.o $(CXX_OPTS) $(INCLUDE)

##############################
######    AUXILIARY    #######
##############################

$(OBJ)/Thread.o : $(AUXILIARY)/Thread.cpp $(AUXILIARY)/Thread.h
	$(SRC_COMPILER) -c $(AUXILIARY)/Thread.cpp -o $(OBJ)/Thread.o $(CXX_OPTS) $(INCLUDE)

##############################
######      META       #######
##############################

##############################
######   META_UTIL     #######
##############################

$(OBJ)/MIApplication.o : $(META_UTIL)/MIApplication.cpp $(META_UTIL)/MIApplication.h
	$(SRC_COMPILER) -c $(META_UTIL)/MIApplication.cpp -o $(OBJ)/MIApplication.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/MIUser.o : $(META_UTIL)/MIUser.cpp $(META_UTIL)/MIUser.h
	$(SRC_COMPILER) -c $(META_UTIL)/MIUser.cpp -o $(OBJ)/MIUser.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/MIRole.o : $(META_UTIL)/MIRole.cpp $(META_UTIL)/MIRole.h
	$(SRC_COMPILER) -c $(META_UTIL)/MIRole.cpp -o $(OBJ)/MIRole.o $(CXX_OPTS) $(INCLUDE)

##############################
######   META_CLIENT   #######
##############################

$(OBJ)/MI_client.o : $(META_CLIENT)/MI_client.cpp $(META_CLIENT)/MI_client.h
	$(SRC_COMPILER) -c $(META_CLIENT)/MI_client.cpp -o $(OBJ)/MI_client.o $(CXX_OPTS) $(CXX_OPTS_MYSQL) $(INCLUDE)

$(OBJ)/MIServiceConnector.o : $(META_CLIENT)/MIServiceConnector.cpp $(META_CLIENT)/MIServiceConnector.h
	$(SRC_COMPILER) -c $(META_CLIENT)/MIServiceConnector.cpp -o $(OBJ)/MIServiceConnector.o $(CXX_OPTS) $(CXX_OPTS_MYSQL) $(INCLUDE)

$(OBJ)/collaboration_subsystem.o : $(META_CLIENT)/collaboration_subsystem.cpp $(META_CLIENT)/collaboration_subsystem.h
	$(SRC_COMPILER) -c $(META_CLIENT)/collaboration_subsystem.cpp -o $(OBJ)/collaboration_subsystem.o $(CXX_OPTS) $(CXX_OPTS_MYSQL) $(INCLUDE)

##############################
###   META_CLIENT_DEFAULTS  ##
##############################

$(OBJ)/MIListener.o : $(META_CLIENT_DEFAULTS)/MIListener.cpp $(META_CLIENT_DEFAULTS)/MIListener.h
	$(SRC_COMPILER) -c $(META_CLIENT_DEFAULTS)/MIListener.cpp -o $(OBJ)/MIListener.o $(CXX_OPTS) $(CXX_OPTS_MYSQL) $(INCLUDE)

$(OBJ)/MIEvent.o : $(META_CLIENT_DEFAULTS)/MIEvent.cpp $(META_CLIENT_DEFAULTS)/MIEvent.h
	$(SRC_COMPILER) -c $(META_CLIENT_DEFAULTS)/MIEvent.cpp -o $(OBJ)/MIEvent.o $(CXX_OPTS) $(INCLUDE)
	
$(OBJ)/pairEvent.o : $(META_CLIENT_DEFAULTS)/pairEvent.cpp $(META_CLIENT_DEFAULTS)/pairEvent.h
	$(SRC_COMPILER) -c $(META_CLIENT_DEFAULTS)/pairEvent.cpp -o $(OBJ)/pairEvent.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/drawingEvent.o : $(META_CLIENT_DEFAULTS)/drawingEvent.cpp $(META_CLIENT_DEFAULTS)/drawingEvent.h
	$(SRC_COMPILER) -c $(META_CLIENT_DEFAULTS)/drawingEvent.cpp -o $(OBJ)/drawingEvent.o $(CXX_OPTS) $(INCLUDE)
	
$(OBJ)/drawingListener.o : $(META_CLIENT_DEFAULTS)/drawingListener.cpp $(META_CLIENT_DEFAULTS)/drawingListener.h
	$(SRC_COMPILER) -c $(META_CLIENT_DEFAULTS)/drawingListener.cpp -o $(OBJ)/drawingListener.o $(CXX_OPTS) $(INCLUDE)

##############################
######   META_SERVER   #######
##############################

$(OBJ)/dbAccessor.o : $(META_SERVER)/dbAccessor.cpp $(META_SERVER)/dbAccessor.h
	$(SRC_COMPILER) -c $(META_SERVER)/dbAccessor.cpp -o $(OBJ)/dbAccessor.o $(CXX_OPTS) $(CXX_OPTS_MYSQL) $(INCLUDE)

$(OBJ)/dbConnector.o : $(META_SERVER)/dbConnector.cpp $(META_SERVER)/dbConnector.h
	$(SRC_COMPILER) -c $(META_SERVER)/dbConnector.cpp -o $(OBJ)/dbConnector.o $(CXX_OPTS) $(CXX_OPTS_MYSQL) $(INCLUDE)

$(OBJ)/MI_server.o : $(META_SERVER)/MI_server.cpp $(META_SERVER)/MI_server.h
	$(SRC_COMPILER) -c $(META_SERVER)/MI_server.cpp -o $(OBJ)/MI_server.o $(CXX_OPTS) $(CXX_OPTS_MYSQL) $(INCLUDE)	

##############################
#######     MAIN       #######
##############################

$(OBJ)/debug.o : $(MAIN)/debug.cpp $(MAIN)/debug.h
	$(SRC_COMPILER) -c $(MAIN)/debug.cpp -o $(OBJ)/debug.o $(CXX_OPTS) $(CXX_OPTS_MYSQL) $(INCLUDE)	

$(OBJ)/test_client.o : $(MAIN)/test_client.cpp
	$(SRC_COMPILER) -c $(MAIN)/test_client.cpp -o $(OBJ)/test_client.o $(CXX_OPTS) $(INCLUDE)

$(OBJ)/MIService.o : $(META_SERVER)/MIService.cpp
	$(SRC_COMPILER) -c $(META_SERVER)/MIService.cpp -o $(OBJ)/MIService.o $(CXX_OPTS) $(INCLUDE)
